<%--
  Created by IntelliJ IDEA.
  User: 123456
  Date: 2023/5/25
  Time: 10:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>Title</title>
        <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.js"></script>
        <style>
            * {margin: 0;padding: 0;}

            html {height: 100%;width: 100%;}

            body {
                height: 100%;
                width: 100%;
                display: flex;
                justify-content: space-between;
            }

            .container {
                height: 100%;
                width: 100%;
                background-color: antiquewhite;
            }

            .left{
                width: 35%;
                height: 100%;
                /* background-color:burlywood; */
                background-image: linear-gradient(to bottom,burlywood,brown);
                display: flex;
                justify-content: center;
                align-items: center;
            }
            .ti{
                width: 80%;
                height: 80%;
                display: flex;
                flex-direction: column;
            }
            .big {
                background-image: linear-gradient(to right, #a9c4f2, rgb(173, 173, 173));
                width: 400px;
                height: 388px;
                border-radius: 50px;
                padding: 0 50px;
                position: relative;
                left: 40%;
                top: 50%;
                transform: translate(-50%, -50%);
            }

            .header {
                font-size: 60px;
                font-weight: 900;
                text-align: center;
                line-height: 120px;
            }

            .input-item {
                display: block;
                width: 100%;
                margin-bottom: 20px;
                border: 0;
                padding: 10px;
                border-bottom: 1px solid rgb(128, 125, 125);
                font-size: 15px;
                outline: none;
            }
            .login {
                text-align: center;
                padding: 10px;
                width: 100%;
                margin-top: 40px;
                background-color: cornflowerblue;
                color: white;
            }

            .msg {
                text-align: center;
                line-height: 88px;
            }

            a {
                text-decoration-line: none;
                color: cornflowerblue;
            }
        </style>
    </head>
    <body>
        <div class="left">
            <div class="ti">
                <div style="font-size: 55px;font-family:'Times New Roman', Times, serif">BookCLub</div>
                <div style="font-size: 30px;margin-top: 40px;">一个开放的阅读讨论平台，可以在这里进行思维的碰撞，灵魂的交流</div>
            </div>
        </div>
        <div class="container">
            <div class="big">
                <div class="header">登录</div>
                <form class="form-wrapper" action="/login" method="post" name="form1" id="form1" onsubmit="return false">
                    <input type="text"  name="username" placeholder="请输入用户名" class="input-item">
                    <input type="password" name="password" placeholder="请输入密码" class="input-item">
                    <input type="submit" class="login" id="login" value="登录" onclick="onlogin()">
                </form>
                <iframe id="rfFram" name="rfFram" style="display: none"></iframe>
                <div class="msg">
                    没有账号？
                    <a href="Register.jsp">点击注册</a>
                </div>
            </div>
        </div>
    <div style="display: none" id="ifRegister"><%=request.getAttribute("ifRegister")%></div>
    </body>
</html>
<script type="text/javascript">
    onlogin=function (){
        var serchForm=$('#form1').serializeArray();
        var username=serchForm[0].value;
        var password=serchForm[1].value;
        $.ajax({
            "url":'/login',
            'type':"post",
            "data":{
                username:username,
                password:password
            },
            "dataType":"text",
            "xhrFields":{
                "withCredentials":true
            },
            "success":function (data,response,xhr){
                console.log("success")

            },
            "error":function (response){
                alert(response)
                console.log(response)
            },
            "complete":function (XMLHttpRequest){
                alert(XMLHttpRequest.responseText)
                if (XMLHttpRequest.responseText=="登录成功"){
                    location.href="Homepage.jsp";
                }
            }

        })
    }
    window.onload=function (){
        var u=document.getElementById('ifRegister').innerText;
        if(u=="true"){
            alert("注册成功");
        }
    }
</script>
